Skip to content

Update .sub_T when temperature is time dependent#1128

Open
RemDelaporteMathurin wants to merge 4 commits intomainfrom
update-sub-T
Open

Update .sub_T when temperature is time dependent#1128
RemDelaporteMathurin wants to merge 4 commits intomainfrom
update-sub-T

Conversation

@RemDelaporteMathurin
Copy link
Copy Markdown
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin commented Apr 28, 2026

Description

Summary

This PR fixes a bug where the space- and time-dependent temperature was not updated when used in DirichletBCs.

Related Issues

Related to #1060 and #1007

Motivation and Context

Following #1060 we added the .sub_T attribute to subdomains in order to work around FEniCS/dolfinx#3207

However, we don't update in time this .sub_T if the temperature is time dependent.

Consider the following MWE (run on main) where the BC is $c = 2 T$ on the boundary:

from mpi4py import MPI
import dolfinx
import festim as F

my_model = F.HydrogenTransportProblemDiscontinuous()

n = 8
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, n, n)
my_model.mesh = F.Mesh(mesh)

surface_1 = F.SurfaceSubdomain(id=1)

material_1 = F.Material(D_0=1, E_D=0, name="material_1")
volume_1 = F.VolumeSubdomain(id=2, material=material_1)

my_model.subdomains = [surface_1, volume_1]

H = F.Species(name="H", subdomains=my_model.volume_subdomains)
my_model.species = [H]


my_model.boundary_conditions = [
    F.FixedConcentrationBC(species=H, subdomain=surface_1, value=lambda T: 2 * T)
]

my_model.temperature = lambda t, x: 1 + x[0] + x[1] + t

my_model.settings = F.Settings(final_time=1, atol=1e-9, rtol=1e-9, stepsize=0.1)

avg_surf = F.AverageSurface(field=H, surface=surface_1)
my_model.exports = [avg_surf]

my_model.initialise()
my_model.run()

print(avg_surf.data)

The average surface concentration should increase in time but:

[4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🔨 Code refactoring (no functional changes, no API changes)
  • 📝 Documentation update
  • ✅ Test update (adding missing tests or correcting existing tests)
  • 🔧 Build/CI configuration change

Testing

  • All existing tests pass locally (pytest)
  • I have added new tests that prove my fix is effective or that my feature works

Code Quality Checklist

  • My code follows the code style of this project (Ruff formatted: ruff format .)
  • My code passes linting checks (ruff check .)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

Documentation

  • I have updated the documentation accordingly (if applicable)
  • I have added docstrings to new functions/classes following the project conventions

Breaking Changes

Screenshots/Examples

Additional Notes

@RemDelaporteMathurin RemDelaporteMathurin added the bug Something isn't working label Apr 28, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.91%. Comparing base (35b86fe) to head (10f4794).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1128      +/-   ##
==========================================
+ Coverage   94.90%   94.91%   +0.01%     
==========================================
  Files          44       44              
  Lines        3376     3385       +9     
==========================================
+ Hits         3204     3213       +9     
  Misses        172      172              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant